import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

/**
 * Author: Daniel Michalski
 * Date: 14.03.13
 */

public class AvgNums {
    public static void main(String[] args) throws IOException {
        //metoda1();
        metoda2();
    }

    private static void metoda1() throws IOException {
        final String fileName = "test.txt";

        int count = 0;
        double sum = 0.0;

        FileWriter fout = new FileWriter(fileName);
        fout.write("2; 3,4; 5; 6; 7,4; 9,1; 10,5; gotowe");
        fout.close();

        FileReader fin = new FileReader(fileName);

        Scanner scanner = new Scanner(fin);
        scanner.useDelimiter("; ");

        while (scanner.hasNext()) {
            if (scanner.hasNextDouble()) {
                sum += scanner.nextDouble();
                count++;
            } else {
                String str = scanner.next();
                if (str.equals("gotowe")) break;
                else {
                    System.out.println("Błąd formatu danych");
                    return;
                }
            }
        }

        scanner.close();

        System.out.println("Srednia wynosi " + (sum / count));
    }

    private static void metoda2() {
        String instr = "Imię: Tomasz Wiek: 28 ID: 77";

        Scanner scanner = new Scanner(instr);
        scanner.findInLine("Wiek:");

        if (scanner.hasNext())
            System.out.println(scanner.next());
        else
            System.out.println("Błąd!");

        scanner.close();
    }
}
